/*
 * INSANE - Interactive Structural Analysis Environment
 *
 * Copyright (C) 2003-2004
 * Universidade Federal de Minas Gerais
 * Escola de Engenharia
 * Departamento de Engenharia de Estruturas
 *
 * Author's email :     insane@dees.ufmg.br
 * Author's Website :   http://www.dees.ufmg.br/insane
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 * 1307, USA.
 *
 */

package br.ufmg.dees.insane.ui.rich.postp.postp_view.dialog;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import br.ufmg.dees.insane.ui.rich.postp.postp_view.InterfacePostp;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.PostpViewState;

/**
 *
 * @author  Samuel Silva Penna
 */
public class ScaleColorsSettingsDialog extends javax.swing.JFrame {
    
	 /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	// Variables declaration - do not modify
    private JButton choose32Button;
    private JButton choose8Button;
    private JButton viewButton;
    private JButton cancelButton;
    private JButton okButton;
    private JCheckBox scaleOnOffCheckBox;
    private JCheckBox boundOnOffCheckBox;
    private JCheckBox backGroundOnOffCheckBox;
//    private JCheckBox scaleLocationCheckBox;
//    private JCheckBox infLocationCheckBox;
    private JComboBox scalePositionComboBox;
    private JComboBox infoPositionComboBox;
    private JLabel jLabel1;
   // private JLabel jLabel10;
    private JLabel jLabel2;
    private JLabel jLabel3;
    private JLabel jLabel4;
//    private JLabel jLabel5;
//    private JLabel jLabel6;
//    private JLabel jLabel7;
//    private JLabel jLabel8;
//    private JLabel jLabel9;
    private JPanel jPanel1;
    private JPanel jPanel2;
//    private JTextField yLocScaleTextField;
//    private JTextField xLocScaleTextField;
//    private JTextField xLocInfoTextField;
//    private JTextField yLocInfoTextField;
    // End of variables declaration
	
    private InterfacePostp parent;
	
    /** Creates new form TraslationDialog */
	public ScaleColorsSettingsDialog(JInternalFrame parent) {
		this.parent = (InterfacePostp)parent;
		initComponents();
	}
    
    /** Creates new form ScaleColorsSettingsDialog */
    public ScaleColorsSettingsDialog() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
    	this.setTitle("Scale Color Settings");
		Image ico = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Insane64.gif"));
		this.setIconImage(ico);
		this.setSize(new Dimension(447,240));
		this.setMinimumSize(new Dimension(447,240));
		this.setMaximumSize(new Dimension(447,240));
		this.setPreferredSize(new Dimension(447,240));
		this.setResizable(false);
		this.setLocationRelativeTo(parent.getDesktop());
		this.setAlwaysOnTop(true);
       
		jPanel1 = new JPanel();
        jLabel1 = new JLabel();
        scalePositionComboBox = new JComboBox();
        jLabel2 = new JLabel();
        infoPositionComboBox = new JComboBox();
        jPanel2 = new JPanel();
        jLabel3 = new JLabel();
        choose32Button = new JButton();
        scaleOnOffCheckBox = new JCheckBox();
        boundOnOffCheckBox = new JCheckBox();
        backGroundOnOffCheckBox = new JCheckBox();
        choose8Button = new JButton();
        jLabel4 = new JLabel();
        viewButton = new JButton();
        cancelButton = new JButton();
        okButton = new JButton();

        getContentPane().setLayout(null);
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jPanel1.setLayout(null);
        jPanel1.setBorder(BorderFactory.createTitledBorder(null, "Position", TitledBorder.DEFAULT_JUSTIFICATION,
        		TitledBorder.DEFAULT_POSITION, new Font("Arial", 0, 12)));
        
        //Scale Position gui args
        jLabel1.setText("Scale Position");
        jLabel1.setFont(new Font("Arial", 0, 12));
        jPanel1.add(jLabel1);
        jLabel1.setBounds(10, 20, 80, 25);

        scalePositionComboBox.setModel(new DefaultComboBoxModel(new String[] { "Top", "Bottom", "Left", "Right" }));
        scalePositionComboBox.setFont(new Font("Arial", 0, 12));
        jPanel1.add(scalePositionComboBox);
        scalePositionComboBox.setBounds(95, 20, 120, 25);
       // scalePositionComboBox.setBounds(85, 20, 120, 25);
        
        //Info Position gui args
        jLabel2.setText("Info Position");
        jLabel2.setFont(new Font("Arial", 0, 12));
        jPanel1.add(jLabel2);
        jLabel2.setBounds(230, 20, 80, 25);

        infoPositionComboBox.setModel(new DefaultComboBoxModel(new String[] { "TL1", "BL2", "TR3", "BR4" }));
        infoPositionComboBox.setFont(new Font("Arial", 0, 12));
        jPanel1.add(infoPositionComboBox);
        infoPositionComboBox.setBounds(310, 20, 120, 25);
        
        getContentPane().add(jPanel1);
        jPanel1.setBounds(0, 0, 440, 60);
        
        //Panel 2
        jPanel2.setLayout(null);
        jPanel2.setBorder(BorderFactory.createTitledBorder(null, "Palette Colors", TitledBorder.DEFAULT_JUSTIFICATION,
        		TitledBorder.DEFAULT_POSITION, new Font("Arial", 0, 12)));
        
        jLabel3.setText("Palette 32 Colors");
        jLabel3.setFont(new Font("Arial", 0, 12));
        jPanel2.add(jLabel3);
        jLabel3.setBounds(10, 30, 95, 25);

        choose32Button.setText("Choose");
        choose32Button.setFont(new Font("Arial", 0, 12));
        jPanel2.add(choose32Button);
        choose32Button.setBounds(110, 30, 80, 25);

        jLabel4.setText("Palette 8 Colors");
        jLabel4.setFont(new Font("Arial", 0, 12));
        jPanel2.add(jLabel4);
        jLabel4.setBounds(250, 30, 95, 25);
        
        choose8Button.setText("Choose");
        choose8Button.setFont(new Font("Arial", 0, 12));
        jPanel2.add(choose8Button);
        choose8Button.setBounds(345, 30, 80, 25);
        
        scaleOnOffCheckBox.setText("Scale Colors On/Off");
        scaleOnOffCheckBox.setFont(new Font("Arial", 0, 12));
        scaleOnOffCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        scaleOnOffCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jPanel2.add(scaleOnOffCheckBox);
        scaleOnOffCheckBox.setBounds(10, 80, 125, 15);

        backGroundOnOffCheckBox.setText("Background On/Off");
        backGroundOnOffCheckBox.setFont(new Font("Arial", 0, 12));
        backGroundOnOffCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        backGroundOnOffCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jPanel2.add(backGroundOnOffCheckBox);
        backGroundOnOffCheckBox.setBounds(165, 80, 125, 15);
        
        boundOnOffCheckBox.setText("Boundary On/Off");
        boundOnOffCheckBox.setFont(new Font("Arial", 0, 12));
        boundOnOffCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        boundOnOffCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jPanel2.add(boundOnOffCheckBox);
        boundOnOffCheckBox.setBounds(310, 80, 110, 15);

        getContentPane().add(jPanel2);
        jPanel2.setBounds(0, 60, 440, 110);

        viewButton.setText("View");
        viewButton.setFont(new Font("Arial", 0, 12));
        getContentPane().add(viewButton);
        viewButton.setBounds(40, 180, 73, 23);

        cancelButton.setText("Cancel");
        cancelButton.setFont(new Font("Arial", 0, 12));
        getContentPane().add(cancelButton);
        cancelButton.setBounds(260, 180, 73, 23);

        okButton.setText("OK");
        okButton.setFont(new Font("Arial", 0, 12));
        getContentPane().add(okButton);
        okButton.setBounds(340, 180, 73, 23);

        
       choose32Button.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						new ColorsPalete32ChooserDialog(parent,parent.getView().getViewState());
					}
				});
        
        choose8Button.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						new ColorsPalete8ChooserDialog((InterfacePostp)parent,parent.getView().getViewState());
					}
				});
        
        viewButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						view();
					}
				});
        
        cancelButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						close();
					}
				});
        
        okButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						view();
						close();
					}
				});
        
        setUp();
    }// </editor-fold>
    
    public void close(){
		this.dispose();
	}
    
    private void setUp(){
    	this.scalePositionComboBox.setSelectedItem(((PostpViewState)parent.getView().getViewState()).getScaleColorsViewState().getScalePosition());
    	this.infoPositionComboBox.setSelectedItem(((PostpViewState)parent.getView().getViewState()).getScaleColorsViewState().getInfoPosition());
    	this.scaleOnOffCheckBox.setSelected(((PostpViewState)parent.getView().getViewState()).getScaleColorsViewState().isScaleContoursOnOff());
    	this.backGroundOnOffCheckBox.setSelected(((PostpViewState)parent.getView().getViewState()).getScaleColorsViewState().isBackgroundOnOff());
    	this.boundOnOffCheckBox.setSelected(((PostpViewState)parent.getView().getViewState()).getScaleColorsViewState().isBoundaryOnOff());
    }
    
    private void view(){
    	((PostpViewState)parent.getView().getViewState()).getScaleColorsViewState().setScalePosition((String)this.scalePositionComboBox.getSelectedItem());
    	((PostpViewState)parent.getView().getViewState()).getScaleColorsViewState().setInfoPosition((String)this.infoPositionComboBox.getSelectedItem());
    	((PostpViewState)parent.getView().getViewState()).getScaleColorsViewState().setScaleContoursOnOff(this.scaleOnOffCheckBox.isSelected());
    	((PostpViewState)parent.getView().getViewState()).getScaleColorsViewState().setBackgroundOnOff(this.backGroundOnOffCheckBox.isSelected());
    	((PostpViewState)parent.getView().getViewState()).getScaleColorsViewState().setBoundaryOnOff(this.boundOnOffCheckBox.isSelected());
    	parent.getView().getController().compose();
		parent.getView().getDrawingArea().repaint();
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ScaleColorsSettingsDialog().setVisible(true);
            }
        });
    }
    
   
    
}

